package com.robot.web;

import java.util.ArrayList;
import java.util.List;

import org.primefaces.context.RequestContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.robot.dto.UserDTO;
import com.robot.service.UserService;

public class UserRegistrationController {

	// private String userName;

	@Autowired
	private UserService userService;

	private UserDTO userSelected;

	private List<UserDTO> userRegisters = new ArrayList<UserDTO>();

	public UserRegistrationController() {
		System.out.println("inicializando UserRegistrationController");
	}

	public void listAllUser() {
		this.userRegisters = userService.listAllUsers();
	}

	public List<UserDTO> getUserRegisters() {
		this.listAllUser();
		return userRegisters;
	}

	public void setUserRegisters(List<UserDTO> userRegisters) {
		this.userRegisters = userRegisters;
	}

	public void eliminarUsuario() {
		System.out.println("datos de usuario seleccionado "
				+ this.userSelected.getUserName());
		userService.eliminarUsuario(userSelected.getId());
		RequestContext context = RequestContext.getCurrentInstance();
		context.addCallbackParam("view", "control_administrador.xhtml");
		// userService.eliminarUsuario(userName);
	}

	public UserDTO getUserSelected() {
		return userSelected;
	}

	public void setUserSelected(UserDTO userSelected) {
		this.userSelected = userSelected;
	}

}
